package com.yb.core.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/10 14:11
 * FileName: Md5Util
 * Description:
 */

@Slf4j
public class Md5Util {
    public static String getMd5(InputStream is){
        String md5 = "";
        try {
             md5 = DigestUtils.md5DigestAsHex(is);
        } catch (IOException e) {
            log.error(String.valueOf(e));
        }
        return md5;
    }

    public static String getMd5(String origin){
        String md5 = "";

        md5 = DigestUtils.md5DigestAsHex(origin.getBytes(StandardCharsets.UTF_8));

        return md5;
    }
}
